package de.homelabs.bookmarkmanager.desktop.qt;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import spiffy.log4j.LoggerHelper;

import com.trolltech.qt.gui.QApplication;

import de.homelabs.bookmarkmanager.desktop.qt.signal.AnnotationSignalHandler;
import de.homelabs.bookmarkmanager.desktop.qt.view.BookmarkManagerMainView;

/**
 * Main Application
 * 
 * @author d.mueller
 *
 */
public class BookmarkManager {
	
	//logger
	 public static final Logger logger = LoggerHelper.getLogger();
	 
	/**
	 * static main function
	 * @param args
	 * @throws NoSuchFieldException 
	 * @throws SecurityException 
	 * @throws IllegalAccessException 
	 * @throws IllegalArgumentException 
	 */
	public static void main(String[] args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
		logger.debug("starting app!");
		QApplication.initialize(args);
		
		
		//application context
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		
			
		//register all signal handlers with @Signal Annotation
		AnnotationSignalHandler annotationSignalHandler = (AnnotationSignalHandler) context.getBean("annotationSignalHandler");
		annotationSignalHandler.registerSignalHandler(context);
		
		//main app
		BookmarkManagerMainView mainView = (BookmarkManagerMainView) context.getBean("bookmarkManagerMainView");
		mainView.initUI();
		mainView.setWindowTitle("Bookmarkmanager");
		mainView.show();
		
		QApplication.exec();
		
	}
	
	/*
	 * read resources
	 * 
	 * Resource resource = context.getResource("classpath:core-menu.xml");
			Reader reader = new InputStreamReader(resource.getInputStream());
	 */
}
